package com.pig4cloud.mall.order.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.mall.order.entity.OrderReturnReason;
import com.pig4cloud.mall.order.service.OrderReturnReasonService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 退货原因表
 *
 * @author fangyu
 * @date 2020-12-25 17:48:03
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/orderreturnreason")
@Api(value = "orderreturnreason", tags = "退货原因表管理")
public class OrderReturnReasonController {

	private final OrderReturnReasonService orderReturnReasonService;

	/**
	 * 分页查询
	 *
	 * @param page              分页对象
	 * @param orderReturnReason 退货原因表
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('order_orderreturnreason_get')")
	public R getOrderReturnReasonPage(Page page, OrderReturnReason orderReturnReason) {
		return R.ok(orderReturnReasonService.page(page, Wrappers.query(orderReturnReason)));
	}


	/**
	 * 通过id查询退货原因表
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('order_orderreturnreason_get')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(orderReturnReasonService.getById(id));
	}

	/**
	 * 新增退货原因表
	 *
	 * @param orderReturnReason 退货原因表
	 * @return R
	 */
	@ApiOperation(value = "新增退货原因表", notes = "新增退货原因表")
	@SysLog("新增退货原因表")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('order_orderreturnreason_add')")
	public R save(@RequestBody OrderReturnReason orderReturnReason) {
		return R.ok(orderReturnReasonService.save(orderReturnReason));
	}

	/**
	 * 修改退货原因表
	 *
	 * @param orderReturnReason 退货原因表
	 * @return R
	 */
	@ApiOperation(value = "修改退货原因表", notes = "修改退货原因表")
	@SysLog("修改退货原因表")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('order_orderreturnreason_edit')")
	public R updateById(@RequestBody OrderReturnReason orderReturnReason) {
		return R.ok(orderReturnReasonService.updateById(orderReturnReason));
	}

	/**
	 * 通过id删除退货原因表
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id删除退货原因表", notes = "通过id删除退货原因表")
	@SysLog("通过id删除退货原因表")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('order_orderreturnreason_del')")
	public R removeById(@PathVariable Long id) {
		return R.ok(orderReturnReasonService.removeById(id));
	}

}
